<?php
/**
 * A simple description for this script
 *
 * PHP Version 5.2.0 or Upper version
 *
 * @package    Paylog
 * @author     Hidehito NOZAWA aka Suin <http://suin.asia>
 * @copyright  2010 Hidehito NOZAWA
 * @license    http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2
 *
 */

class Paylog_Controller_Default extends Paylog_Abstract_Controller
{
	protected $bookHand = null;
	protected $relBookUserHand = null;

	protected $userId = null;

	public function __construct()
	{
		parent::__construct();
		$this->bookHand = new Paylog_Object_BookHandler;
		$this->relBookUserHand = new Paylog_Object_RelBookUserHandler;

		$this->userId = Paylog::$cms->userId;
		$this->userId = (int) Paylog::get('uid', $this->userId);
	}

	public function main()
	{
		$this->_validateAccess();
		$this->_default();
	}

	protected function _validateAccess()
	{
		if ( !$this->userId )
		{
			Paylog::redirect("Please select user or login.");
		}
	}

	protected function _default()
	{
		$bookObjs = $this->bookHand->loadByUserId($this->userId);

		$books = array();

		foreach ( $bookObjs as $bookObj )
		{
			$books[] = array(
				'id'   => $bookObj->getVar('id'),
				'name' => $bookObj->getVar('name'),
			);
		}

		$this->output['books'] = $books;
		$this->_view();
	}
}

?>
